﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Text;
using System.Collections.Generic;

namespace Jy123.Web.Module.Club
{
    public class Club_Coche : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string type = context.Request.QueryString["Type"];
            string cIdString = context.Request.QueryString["ClubId"];
            if (!string.IsNullOrEmpty(cIdString))
            {
                int cId = int.Parse(cIdString);
                Jy123.BLL.Club_Main BLLClub = new Jy123.BLL.Club_Main();
                Jy123.Model.Club_Main club = BLLClub.GetModel(cId);
                StringBuilder sbString = new StringBuilder();
                Jy123.BLL.Club_StarRecord BLLRecord = new Jy123.BLL.Club_StarRecord();
                Jy123.BLL.Club.CModule BLLCModule = new Jy123.BLL.Club.CModule();
                List<Jy123.Model.Club_StarRecord> listRecord = BLLCModule.GetClubStar(cId);
                Jy123.BLL.Public_Star BLLStar = new Jy123.BLL.Public_Star();
                List<Jy123.Model.Public_Star> listStar = BLLStar.GetModelList(string.Empty);
                Dictionary<int, Jy123.Model.Public_Star> dicStar = new Dictionary<int, Jy123.Model.Public_Star>();
                foreach (Jy123.Model.Public_Star star in listStar)
                {
                    dicStar.Add(star.ID, star);
                }
                foreach (Jy123.Model.Club_StarRecord record in listRecord)
                {
                    Jy123.Model.Public_Star cStar = dicStar[record.FStar.Value];
                    string strStar = context.Cache["clubcoche"].ToString();
                    strStar = strStar.Replace("$CocheImage$", cStar.Model);
                    strStar = strStar.Replace("$CocheName$", cStar.SName);
                    strStar = strStar.Replace("$CocheDescription$", cStar.Description);
                    strStar = strStar.Replace("$Skill$", cStar.Skill.Value.ToString());
                    strStar = strStar.Replace("$Physical$", cStar.PhysicalFitness.Value.ToString());
                    strStar = strStar.Replace("$Liveness$", cStar.Liveness.Value.ToString());
                    strStar = strStar.Replace("$Moral$", cStar.Moral.Value.ToString());
                    strStar = strStar.Replace("$Exp$", cStar.Experience.Value.ToString());
                    sbString.Append(strStar);
                }
                if (sbString.Length > 0)
                {
                    context.Response.Write(sbString.ToString());
                }
                else
                {
                    context.Response.Write("你还没有任何教练，请去教练市场购买");
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
